﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Baosight.ZNH.ZMCommon;
using System.Windows.Controls.Data;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCB.UI.PopWindows;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Telerik.Windows.Controls;
using Baosight.Platform.Core.ServiceModel;
using Baosight.Platform.Core.UI.Controls;
using System.Collections.ObjectModel;
using GanttView.Charts.Common.Interface;
using GanttView.Charts.Common.Instance;
using GanttView.Charts.Enum;
using GanttView.Charts.Common.ItemClass;
using GanttView.Charts.Common;
using GanttView.Charts;

namespace Baosight.ZNH.ZMCB.UI
{
    public partial class ZMCB30 : EFViewCmes
    {
        private static string uniqueIdPath = "fdKeyId", taskNamePath = "fdPlace", startDatePath = "fdBeginDate", endDatePath = "fdEndDate", percentCompletePath = "fdComPercent";
        
        string loginId = "";
        //string fdYear = "";
        //string fdstatus = "";
        public ZMCB30()
        {
            InitializeComponent();
            this.Gantt.Loaded += new RoutedEventHandler(Gantt_Loaded);
        }

        /// <summary>
        /// 加载Gantt图的数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Gantt_Loaded(object sender, RoutedEventArgs e)
        {
            UpdateGanttData();
            //this.Gantt.TreeGrid.PreparingCellForEdit += new EventHandler<DataGridPreparingCellForEditEventArgs>(TreeGrid_PreparingCellForEdit);
        }

        /// <summary>
        /// 编辑表格中的单元格之前
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //private void TreeGrid_PreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e)
        //{
        //    DataGridTemplateColumn col = e.Column as DataGridTemplateColumn;
        //    if ("工作地点".Equals(col.Header))
        //    {
        //        object type = (e.Row.DataContext as TaskEntryLayoutItem).Data.ExtendAttributes["fdPlaceType"];
        //        if ("采面".Equals(type))
        //        {
        //            col.CellEditingTemplate = (DataTemplate)Resources["WorkfaceComboBox"];
        //        }
        //        else
        //        {
        //            col.CellEditingTemplate = (DataTemplate)Resources["RaodwayComboBox"];
        //        }
        //    }
        //}

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="initData"></param>
        public override void Initialize(Baosight.Platform.Core.EIInfo initData)
        {
            //fdstatus = initData.Get("fdStatus").ToString();
            loginId = initData.Get("loginId").ToString();
            //fdYear = initData.Get("fdYear").ToString();
            base.Initialize(initData);
            if (initData.Get("hasSimulate").Equals("1"))
            {
                IDictionary<String,String> args = new Dictionary<string, string>();
                args.Add("fdYear", initData.Get("fdYear").ToString());
                Shell.LoadView("ZMCB31",args);
                //Shell.LoadView("ZMCB31");
            }
            else
            {
                if (!initData.Attributes.ContainsKey("fdKeyId"))
                {
                    OpenAddPopup(initData.Get("loginId") as string);
                }
                else
                {
                    //UpdateHeaderData(initData);
                    UpdateHeaderData(initData);
                    ControlButton(initData.Get("fdStatus") as string);
                }
            }
        }

        /// <summary>
        /// 根据不同的主表状态控制按钮是否可用
        /// </summary>
        /// <param name="status"></param>
        private void ControlButton(string status)
        {
            if ("草拟".Equals(status))
            {
                Button btn = this.FindName("SAVE") as Button;
                if (btn != null)
                    btn.IsEnabled = true;
                btn = this.FindName("INVALID") as Button;
                if (btn != null)
                    btn.IsEnabled = true;
                btn = this.FindName("PUBLISH") as Button;
                if (btn != null)
                    btn.IsEnabled = true;
                btn = this.FindName("PRINT") as Button;
                if (btn != null)
                    btn.IsEnabled = true;
                btn = this.FindName("VIEWLIST") as Button;
                if (btn != null)
                    btn.IsEnabled = true;
                this.add.IsEnabled = true;
                this.delete.IsEnabled = true;

            }
            else
            {
                Button btn = this.FindName("save") as Button;
                if (btn != null)
                    btn.IsEnabled = false;
                btn = this.FindName("INVALID") as Button;
                if (btn != null)
                    btn.IsEnabled = false;
                btn = this.FindName("publish") as Button;
                if (btn != null)
                    btn.IsEnabled = false;
                this.add.IsEnabled = false;
                this.delete.IsEnabled = false;
                if ("无计划".Equals(status))
                {
                    btn = this.FindName("PRINT") as Button;
                    if (btn != null)
                        btn.IsEnabled = false;
                    btn = this.FindName("VIEWLIST") as Button;
                    if (btn != null)
                        btn.IsEnabled = false;
                }
                else
                {
                    btn = this.FindName("PRINT") as Button;
                    if (btn != null)
                        btn.IsEnabled = true;
                    btn = this.FindName("VIEWLIST") as Button;
                    if (btn != null)
                        btn.IsEnabled = true;
                }
            }
            if ("生效".Equals(status))
            {
                Button btn = this.FindName("ADJUST") as Button;
                if (btn != null)
                {
                    btn.IsEnabled = true;
                }
            }
            else
            {
                Button btn = this.FindName("ADJUST") as Button;
                if (btn != null)
                {
                    btn.IsEnabled = false;
                }
            }
        }

        /// <summary>
        /// 更新主表页面数据
        /// </summary>
        /// <param name="info"></param>
        private void UpdateHeaderData(EIInfo info)
        {
            this.title.Text = info.Get("fdChartName") as string;
            this.status.Text = info.Get("fdStatus") as string;
 
            if ("1".Equals(info.Get("hasPrevious")))
                this.previous.Visibility = Visibility.Visible;
            else
                this.previous.Visibility = Visibility.Collapsed;

            if ("1".Equals(info.Get("hasNext")))
                this.next.Visibility = Visibility.Visible;
            else
                this.next.Visibility = Visibility.Collapsed;
        }

        /// <summary>
        /// 更新Gantt图页面数据
        /// </summary>
        private void UpdateGanttData()
        {
            if (this.EIDataContext.ContainsBlockName("result"))
            {
                this.Gantt.DataSource = GanttView.Charts.StaticTools.GetTasklistByBlock(this.EIDataContext.GetBlock("result"), uniqueIdPath, taskNamePath, startDatePath, endDatePath, percentCompletePath);
                this.Gantt.Update();
            }
        }

        /// <summary>
        /// 查询计划
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void queryPlan_Click(object sender, RoutedEventArgs e)
        {
            TempHyperlink = sender as HyperlinkButton;
            TempHyperlink.IsEnabled = false;

            Shell.LoadView("ZMCB40");

            TempHyperlink.IsEnabled = true;
        }

        /// <summary>
        /// 上一方案
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void previous_Click(object sender, RoutedEventArgs e)
        {
            TempHyperlink = sender as HyperlinkButton;
            TempHyperlink.IsEnabled = false;

            EIInfo info = new EIInfo();
            info.Set(EIConstants.ServiceNameKey, "ZMCB30");
            info.Set(EIConstants.MethodNameKey, "queryPrevious");
            info.Set("fdKeyId", this.KeyId.Value);
            info.SetBlock(StaticTools.GetBlockByTasklist("result", this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>, uniqueIdPath, taskNamePath, startDatePath, endDatePath, percentCompletePath));
            this.Submit(info, querySubmitCompleted);        

        }

        /// <summary>
        /// 下一方案
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void next_Click(object sender, RoutedEventArgs e)
        {
            TempHyperlink = sender as HyperlinkButton;
            TempHyperlink.IsEnabled = false;

            EIInfo info = new EIInfo();
            info.Set(EIConstants.ServiceNameKey, "ZMCB30");
            info.Set(EIConstants.MethodNameKey, "queryNext");
            info.Set("fdKeyId", this.KeyId.Value);
            info.SetBlock(StaticTools.GetBlockByTasklist("result", this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>, uniqueIdPath, taskNamePath, startDatePath, endDatePath, percentCompletePath));
            this.Submit(info, querySubmitCompleted);   

        }

        /// <summary>
        /// 添加采面或巷道
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void add_Click(object sender, RoutedEventArgs e)
        {
            TempButton = sender as Button;
            TempButton.IsEnabled = false;

            if (this.Gantt.DataSource == null)
            {
                this.Gantt.DataSource = new ObservableCollection<ITaskDescriptor>();
            }
            ObservableCollection<ITaskDescriptor> tasks = this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>;
            ITaskDescriptor task = BulidNewTask();
            tasks.Add(task);
            this.Gantt.Update();

            TempButton.IsEnabled = true;
        }

        /// <summary>
        /// 创建新的任务对象
        /// </summary>
        /// <param name="uintValue"></param>
        /// <param name="placeType"></param>
        /// <returns></returns>
        private ITaskDescriptor BulidNewTask()
        {
            ITaskDescriptor task = new SimpleTaskDescriptor();
            task.TaskType = TaskType.ResourceTask;
            task.ExtendAttributes = new DependencyDictionary<string, object>();
            foreach (string key in this.EIDataContext.GetBlock("result").Columns.Keys)
            {
                if (!key.Equals(uniqueIdPath) && !key.Equals(taskNamePath) && !key.Equals(startDatePath) && !key.Equals(endDatePath) && !key.Equals(percentCompletePath))
                {
                    task.ExtendAttributes[this.EIDataContext.GetBlock("result").Columns[key].Name] = "";
                }
            }
            task.ExtendAttributes["fdForeignKey"] = this.KeyId.Value;
            return task;
        }

        ///// <summary>
        ///// 添加巷道
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //private void addRW_Click(object sender, RoutedEventArgs e)
        //{
        //    TempButton = sender as Button;
        //    TempButton.IsEnabled = false;

        //    DataGridTemplateColumn col = this.Gantt.TreeGrid.Columns[0] as DataGridTemplateColumn;
        //    col.CellEditingTemplate = (DataTemplate)Resources["RaodwayComboBox"];

        //    if (this.Gantt.DataSource == null)
        //    {
        //        this.Gantt.DataSource = new ObservableCollection<ITaskDescriptor>();
        //    }
        //    ObservableCollection<ITaskDescriptor> tasks = this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>;
        //    ITaskDescriptor task = new SimpleTaskDescriptor();
        //    task.TaskType = TaskType.ResourceTask;
        //    task.ExtendAttributes = new DependencyDictionary<string, object>();
        //    task.ExtendAttributes["fdUnit"] = "米";
        //    task.ExtendAttributes["fdPlaceType"] = "巷道";
        //    tasks.Add(task);
        //    this.Gantt.Update();

        //    TempButton.IsEnabled = true;
        //}

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void delete_Click(object sender, RoutedEventArgs e)
        {
            if (this.Gantt.TreeGrid.SelectedItems[0] != null)
            {
                TaskEntryLayoutItem task = this.Gantt.TreeGrid.SelectedItems[0] as TaskEntryLayoutItem;
                ObservableCollection<ITaskDescriptor> tasks = this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>;
                tasks.Remove(task.Data);
                this.Gantt.Update();
            }
        }

        /// <summary>
        /// 弹出添加年计划主表页面
        /// </summary>
        /// <param name="loginId"></param>
        private void OpenAddPopup(string loginId)
        {
            AddYearPlan view = new AddYearPlan("insert");//构造一个新的修改页面
            view.EIDataContext = new Platform.Core.UI.EIDataContext();
            view.EIDataContext.Update(new EIInfo());

            view.fdEditor.Value = loginId;

            CmesWindows _popup = new CmesWindows();//构造一个弹出页面
            _popup.ResizeMode = ResizeMode.NoResize;//设置不能修改窗口大小
            _popup.Header = "年计划-新增";//设置Title
            _popup.Content = view;//让新增页面在弹出窗口显示
            _popup.Closed += new EventHandler<WindowClosedEventArgs>(AddPlanWindow_Closed);
            _popup.ShowDialog();//模态显示弹出窗口
        }

        /// <summary>
        /// 回调函数——关闭添加年计划主表页面后执行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddPlanWindow_Closed(object sender, WindowClosedEventArgs e)
        {
            if (e.DialogResult == true)
            {
                AddYearPlan view = (sender as CmesWindows).Content as AddYearPlan;
                EIInfo info = new EIInfo();
                info.Set(EIConstants.ServiceNameKey, "ZMCB30");
                info.Set(EIConstants.MethodNameKey, "query");
                info.Set("fdKeyId", view.fdKeyId.Value);
                this.Submit(info, querySubmitCompleted);
            }

            //按钮生效
            base.TempButtonOpen(true);
        }

        /// <summary>
        /// 回调函数——查询主表数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void querySubmitCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status >= 0)
            {
                this.EIDataContext.Update(e.EIInfo);
                UpdateHeaderData(e.EIInfo);
                UpdateGanttData();
                ControlButton(e.EIInfo.Get("fdStatus") as string);
            }
            else
            {
                OpenEFWindowAlert("查询出错啦！" + e.EIInfo.Msg, false);
            }

            if (TempButton != null)
                TempButton.IsEnabled = true;
            if (TempHyperlink != null)
                TempHyperlink.IsEnabled = true;
        }

        private void DepComboBox_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
        {
            EFComboBox box = sender as EFComboBox;
            if (box.SelectedItem != null)
            {
                ITaskDescriptor row = ((box.Parent as DataGridCell).DataContext as TaskEntryLayoutItem).Data;
                row.ExtendAttributes["fdDepartment"] = box.SelectedItem.GetType().GetProperty("orgName").GetValue(box.SelectedItem, null);
            }
        }

        private void placeComboBox_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
        {
            EFComboBox box = sender as EFComboBox;
            if (box.SelectedItem != null)
            {
                ITaskDescriptor row = ((box.Parent as DataGridCell).DataContext as TaskEntryLayoutItem).Data;
                row.TaskName = box.SelectedItem.GetType().GetProperty("fdPlace").GetValue(box.SelectedItem, null) as string;
                row.ExtendAttributes["fdSurplus"] = box.SelectedItem.GetType().GetProperty("fdSurplus").GetValue(box.SelectedItem, null);
                row.ExtendAttributes["fdPlan"] = box.SelectedItem.GetType().GetProperty("fdSurplus").GetValue(box.SelectedItem, null);
                row.ExtendAttributes["fdPlaceType"] = box.SelectedItem.GetType().GetProperty("fdPlaceType").GetValue(box.SelectedItem, null);
                row.ExtendAttributes["fdUnit"] = box.SelectedItem.GetType().GetProperty("fdUnit").GetValue(box.SelectedItem, null);
                if ("采面".Equals(box.SelectedItem.GetType().GetProperty("fdPlaceType").GetValue(box.SelectedItem, null)))
                {
                    row.ExtendAttributes["fdLength"] = box.SelectedItem.GetType().GetProperty("fdSurplusLength").GetValue(box.SelectedItem, null);
                    row.ExtendAttributes["fdSurplusLength"] = box.SelectedItem.GetType().GetProperty("fdSurplusLength").GetValue(box.SelectedItem, null);
                    row.ExtendAttributes["fdHeight"] = box.SelectedItem.GetType().GetProperty("fdHeight").GetValue(box.SelectedItem, null);
                    row.ExtendAttributes["fdWidth"] = box.SelectedItem.GetType().GetProperty("fdWidth").GetValue(box.SelectedItem, null);
                    row.ExtendAttributes["fdBulk"] = box.SelectedItem.GetType().GetProperty("fdBulk").GetValue(box.SelectedItem, null);
                    row.ExtendAttributes["fdChance"] = box.SelectedItem.GetType().GetProperty("fdChance").GetValue(box.SelectedItem, null);
                }
            }
        }

        /// <summary>
        /// 点击添加方案按钮，弹出新增页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnAddButtonClick(object sender, RoutedEventArgs e)
        {
            TempButton = sender as Button;
            TempButton.IsEnabled = false;

            OpenAddPopup(loginId);

            TempButton.IsEnabled = true;
        }

        /// <summary>
        /// 点击保存按钮，保存采面和巷道信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public new void OnSaveButtonClick(object sender, RoutedEventArgs e)
        {
            TempButton = sender as Button;
            TempButton.IsEnabled = false;

            EIInfo info = new EIInfo();
            info.Set(EIConstants.ServiceNameKey, "ZMCB30");
            info.Set(EIConstants.MethodNameKey, "save");
            info.Set("fdKeyId", this.KeyId.Value);
            info.SetBlock(StaticTools.GetBlockByTasklist("result", this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>, uniqueIdPath, taskNamePath, startDatePath, endDatePath, percentCompletePath));
            this.Submit(info, SaveSubmitCompleted);
 
        }

        /// <summary>
        /// 保存后的回调函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveSubmitCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status >= 0)
            {
                BaseTools.OpenEFWindowAlert("保存成功！", null);
            }
            else
            {
                BaseTools.OpenEFWindowAlert("出错：" + e.EIInfo.Msg, null);
            }
            TempButton.IsEnabled = true;
        }
        /// <summary>
        /// 点击作废按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnInvalidButtonClick(object sender, RoutedEventArgs e)
        {
            TempButton = sender as Button;
            TempButton.IsEnabled = false;

            BaseTools.OpenEFWindowConfirm("确定作废该计划方案？", InvalidWindowAlertClosed);

        }

        /// <summary>
        /// 作废确认框关闭后
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void InvalidWindowAlertClosed(object sender, WindowClosedEventArgs e)
        {
            if (e.DialogResult == null || !e.DialogResult.Value)
            {
                this.TempButtonOpen(true);//按钮生效
                return;
            }

            EIInfo info = new EIInfo();
            info.Set(EIConstants.ServiceNameKey, "ZMCB30");
            info.Set(EIConstants.MethodNameKey, "invalid");
            info.Set("fdKeyId", this.KeyId.Value);
            info.SetBlock(StaticTools.GetBlockByTasklist("result", this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>, uniqueIdPath, taskNamePath, startDatePath, endDatePath, percentCompletePath));
            this.Submit(info, querySubmitCompleted);
        }

        /// <summary>
        /// 点击发布按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnPublishButtonClick(object sender, RoutedEventArgs e)
        {
            if ("生效".Equals(this.status.Text))
            {
                BaseTools.OpenEFWindowAlert("该方案已发布，不能再发布了！", null);
                return;
            }
            TempButton = sender as Button;
            TempButton.IsEnabled = false;

            //BaseTools.OpenEFWindowConfirm("确定发布该计划方案？", PublishWindowAlertClosed);
            if (ThisValidate())
            {
                BaseTools.OpenEFWindowConfirm("确定发布该计划方案？", PublishWindowAlertClosed);
                return;
            }
            TempButton.IsEnabled = true;

        }

        /// <summary>
        /// 发布确认框关闭后
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PublishWindowAlertClosed(object sender, WindowClosedEventArgs e)
        {
            if (e.DialogResult == null || !e.DialogResult.Value)
            {
                this.TempButtonOpen(true);//按钮生效
                return;
            }

            EIInfo info = new EIInfo();
            info.Set(EIConstants.ServiceNameKey, "ZMCB30");
            info.Set(EIConstants.MethodNameKey, "publish");
            info.Set("fdKeyId", this.KeyId.Value);
            info.SetBlock(StaticTools.GetBlockByTasklist("result", this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>, uniqueIdPath, taskNamePath, startDatePath, endDatePath, percentCompletePath));
            this.Submit(info, publishSubmitCompleted);
        }

        /// <summary>
        /// 回调函数——发布主表数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void publishSubmitCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status >= 0)
            {
                this.EIDataContext.Update(e.EIInfo);
                UpdateData(e.EIInfo);
                UpdateGanttData();
                ControlButton(e.EIInfo.Get("fdStatus").ToString());
                BaseTools.OpenEFWindowAlert("发布成功！", null);
            }
            else
            {
                OpenEFWindowAlert("发布失败啦！" + e.EIInfo.Msg, false);
            }

            if (TempButton != null)
                TempButton.IsEnabled = true;
            if (TempHyperlink != null)
                TempHyperlink.IsEnabled = true;
        }

        /// <summary>
        /// 点击调整按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnAdjustButtonClick(object sender, RoutedEventArgs e)
        {

        }

        /// <summary>
        /// 点击打印按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnPrintButtonClick(object sender, RoutedEventArgs e)
        {

        }

        /// <summary>
        /// 点击查看计划表按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnViewlistButtonClick(object sender, RoutedEventArgs e)
        {
            //Dictionary<string, string> args = new Dictionary<string, string>();
            //args.Add("fdYear",this.fdYear);
            //args.Add("fdStatus", this.status.Text);
            //Shell.LoadView("ZMCB32", args);
            TempButton = sender as Button;
            TempButton.IsEnabled = false;


            if (ThisValidate())
            {
                EIInfo info = new EIInfo();
                info.Set(EIConstants.ServiceNameKey, "ZMCB30");
                info.Set(EIConstants.MethodNameKey, "viewlist");
                info.Set("fdKeyId", this.KeyId.Value);
                info.Set("fdStatus", this.status.Text);
                info.Set("fdYear", this.fdYear.Value);
                info.SetBlock(StaticTools.GetBlockByTasklist("result", this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>, uniqueIdPath, taskNamePath, startDatePath, endDatePath, percentCompletePath));
                this.Submit(info, ViewlistSubmitCompleted);
                return;
            }
            TempButton.IsEnabled = true;
        }

        /// <summary>
        ///按钮查看计划表后的回调函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ViewlistSubmitCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status >= 0)
            {
                S30Viewlist view = new S30Viewlist();
                view.EIDataContext = new Platform.Core.UI.EIDataContext();
                view.EIDataContext.Update(e.EIInfo);

                view.fdKeyId.Value = this.KeyId.Value;
                view.fdStatus.Value = this.status.Text;
                view.fdYear.Value = this.fdYear.Value;
                //view.fdYear.Value = e.EIInfo.Get("fdYear").ToString();

                CmesWindows _popup = new CmesWindows();//构造一个弹出页面
                _popup.WindowStartupLocation = Telerik.Windows.Controls.WindowStartupLocation.CenterOwner;
                _popup.TopOffset = -150;
                _popup.LeftOffset = -80;
                _popup.ResizeMode = ResizeMode.NoResize;//设置不能修改窗口大小
                _popup.Header = view.eTitle;//设置Title
                _popup.Content = view;//让新增页面在弹出窗口显示
                _popup.Closed += new EventHandler<WindowClosedEventArgs>(ViewlistWindow_Closed);
                _popup.ShowDialog();//模态显示弹出窗口
            }
            else
            {
                BaseTools.OpenEFWindowAlert("出错：" + e.EIInfo.Msg, null);
                TempButton.IsEnabled = true;
            }
        }

        /// <summary>
        /// 关闭查看计划表弹出页面后
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ViewlistWindow_Closed(object sender, WindowClosedEventArgs e)
        {
            TempButton.IsEnabled = true;
        }

        /// <summary>
        /// 校验空值
        /// </summary>
        /// <returns></returns>
        private bool ThisValidate()
        {
            ObservableCollection<ITaskDescriptor> tasks = this.Gantt.DataSource as ObservableCollection<ITaskDescriptor>;
            string msg = "";
            for (int i = 0; i < tasks.Count; i++)
            {
                msg += "第" + (i + 1) + "行";
                if (String.IsNullOrEmpty(tasks[i].TaskName))
                {
                    msg += "工作地点不能为空！";
                }
                if ("".Equals(tasks[i].ExtendAttributes["fdDepartment"]))
                {
                    msg += "施工部门不能为空！";
                }
                if ("".Equals(tasks[i].ExtendAttributes["fdPlan"]))
                {
                    msg += "计划总量不能为空！";
                }
                if ("".Equals(tasks[i].ExtendAttributes["fdUnit"]))
                {
                    msg += "单位不能为空！";
                }
                if (default(DateTime).Equals(tasks[i].StartDate))
                {
                    msg += "开始日期不能为空！";
                }
                if (default(DateTime).Equals(tasks[i].EndDate))
                {
                    msg += "结束日期不能为空！";
                }
                if (msg.Substring(msg.Length - 3).Equals("第" + (i + 1) + "行"))
                {
                    msg = msg.Substring(0, msg.Length - 3);
                }
            }
            if (!msg.Equals(""))
            {
                BaseTools.OpenEFWindowAlert(msg, null);
                return false;
            }
            return true;
        }
    }
}
